Minor bug fix and improvements