Restructured JS into tick() architecture