not entirely decent, but i'll clean up and package these algorithms when i've solved all the problems in the first module