refactors nokogiri code