Refactored player logic into functions