refactor player code