moved scheduling into functions for segment and thread