Bug fixes for Database to save plan