refactored code to work with three players