fixed SQL query
fixed check for duplicates (this fixes #4)