style cleanup and fixing a few logic errors
m. rearranged script file to avoid syntax highlighter regex oddities with native syntax highlighting.