Add tests and remove dead code