Added sanity checking to task routine.