ref #4028 - bug fixing and improvements