Refactor some code into helper functions

This just moves some genertic code out of the PlayMotion class, so that it can be used more easily by other code.

This invalidates #2

@po1 @adolfo-rt please review, thanks!