my (tested) implementation of common algorithms