Fix some type issues and a couple of incorrect variable references