Add task scheduler
Fix bug