Fix for database search bug

#724 and unrelated fix