Added timeout, improved error handling