Moved servermainloop and did a bug fix on main loop