Refactor implementation; Unit tests