Cleaned up the Javascript so it looks less disgusting