Improve loading/parsing code. Fix some smaller bugs.