improves algorithm