Bug fixes in several places

Finally I've had some free time to track down some of the bugs that made noteo crash.