minor algorithm changes