Cleaned up scheduling code