Add null checks to TaskContext
Fix minor bug