Added better error handling for invalid connects