Refactor play() function to be more idiomatic.