Added optional secure settings, and refactored URL generation.