Fixed some pretty serious bugs in scheduling and loop handling.