refactored buildIcons function