refactor play function