Fixed all the problems I created from my botched merge and improved some
stuff along the way.