Fixed a few more bugs; cleanup