fixed bug on the database query