Now it is correct (at least seems to be correct) - gradient calculations