refactored checkin query