Made code unit testable
Added unit tests where the last one fails