updates. might be finished, but output numbers look a bit iffy. need to investigate more.