beginning rewrite to clean up the code and enable ie8 compatibility.