Made timeout possible. More code refactoring.