Remove obsolete code and add a few tests