better algorithm solutions