First wave of refactoring

This resolves #13, have started adding tests to verify correct behaviour of module