Refactorings + improvements

A lot of refactoring, adding code coverage, etc.