Remove unused code, add unit tests