cleaned code
Improved SQL query