Cleanup and bugfixes. Yay! It works!