Improved tests and cleanup