Major refactoring + code coverage