Deduplicate task class code
Improve code