Implement timeout option and fix setTimeout bug