Cleanup and improved testing