database entry from Ilia A. Guzei and better error handling