Fixed code based on updated library code

Still doesn't compile, remaining bugs are not quick fixes.