Removed debug statement
Cleaned ugly sql-query code.