barebones implementation of the algorithm in a simple way