A bunch of cleanup and bug fixing