Lot of additional fixes. Now compiles cleanly, still linking fails.