Changed a typo -- 'heartbeatfile' variable name should 'heartbeatFile' and also added a delay before trying to reconnect.