Refactored and cleaned up task system