Refactored, added tests and documented build system