Better port handling with CORS support, added fix for bad encoding