added first version of full algorithm and added log for investigation and bug fix