removed unused logging code
Use query scope instead of manual where clause