removed bug in sql query