Various bug fixes, various improvements