adding delete and better error handling