Various bug-fixes