Split some code into separate classes.

Fixed player inventory sorting problem.