wtf
cleaned up algorithm
merge