Added timeout against DoS, thanks to Chris Eppstein for a solution