Removed dead code and fixing up tests