Updated scheduling with better queries and refactored