Fixed bug when trying to connect to a client before having scanned any; Code cleanup.