[#1397 #1543 #1540] misc bug fixes