Refactor play() logic to make it more readable