added multiplayer functionality and cleaned up code