finished implementing algorithm; needs to be debugged