Updated the shaping algorithm