Forked over some utility methods from my game.