Added reconnection functionality with configurable timeout