Processed Scott's feedback. Db endpoint slightly safer, some refactorings.