Player management (issue #3)

This should deal with that issue. There are quite a bit of changes. And still needs some more refactoring but it works.

Also wrote unit tests.