refactor with create_connection function