refactored loop. removed getPyramidal function