Optimizing PLC Software with Layered Architecture