Refactor functions

Intent was to make them more readable & slightly more efficient by caching DOM
elements/HTML collections. Needs more work.