Added CreateTask function and started releated event logic.