Use a more intelligent algorithm