Fixed connection bug and added better logging