more bugfixes, fix random things, start using algorithm