Small code fixes and improvements