added onbeforeunload warning, improved formatting