Fixes and cleanup

I will be adding more while I try to make this work. Continuouse review would be nice :)