Remove legacy code, refactor tests