added tags functionality. tests pass. refactored code