Fleshed out changes

Your recent changes on your fork fixed some of my errors, but I thought I'd fix up the rest rather than simply telling you what I thought should change. This compiles with my project as-is, and doesn't have many changes from yours.