bug fix
refactored query