Main system code