Minor refactoring + Adds unit tests