cleaned up code, moved logic to different files