Some changes according to the comments by Dima