Fixed another set of bugs. Needs testing. May be final.