twiddled with algorithm to create better results with less artifacts