worst algorithm ever. it works