reorganizes the code

It no longer throws Chrome CSP errors, meaning no in-line scripts.