adding check_connections, code cleanup