completed shapeFit function