Various bug fixes etc