Added http/s check and cleaned up receive code