Fully functional refactor including steps towards PEP8 and fixing of
major bug when applying unmatched tags