enhance code and fix non ssl connections