Move code which is used by the user into a module

This means that the user can now import all they need with the usual
`from sr import *` command.