refactored tags.rb to reduce complexity