Reverse proxy works with SSL

Fix for issue #152 and small reorganization of code to establish ssl connections.