Added some deletion and error handling