Created/improved scheduler_loop. Added close() function.