Refactor play function.