Upgraded code with respect to last remarks.