Fix minor issues: throw error before socket check, remove unused var