Updated for further API changes, and made the code less dependant on the concept of a player