Cleanup function, fixed HTTPS detection
Fixed Javascript handle