Remove dead code and add unit test