fixed query writing