Improve session and https handling