Fix some bugs and add a server tick handler