Added partial bug fix and improvements