bug fixing and improvements