updated with SSL support and headers