finish implementation, fix algorithms, refactor