added timeout option. Need to fix exceptions and conrner cases