Refactoring. Added some basic tests.