Reworked implementation with test coverage