refactor
write queries to log in debug mode