Testing and some more refactoring

Just a start with some basic things.