Various old bug fixes and improvements