Wayyy too large of a script to be in-line, pull this out into a separate file