refactored basis stuff using rep from StatsBase