Refactored everything into a single tag; improved logic