fixing parsing bugs and refactoring markup