Further fixes and tweaks. Now working for the most part.