Solved a number of annoying bugs.