refactor byAttribute to stateless