Replaced a lot of unnecessarily complex (and easily broken) logic with simple RAII scope guards (magic system is a good [temporary] example of this).