made my algorithm nicer