Fix bug with delete entry returning 500
code tidy