fixes player id bug and some code restructuring