Refactoring + Fixing the unit tests