Final commit, lots of bug fixes