Separated essential code and inputs code. Added a tick counter