Clean up of schedule function