made some changes advised by @ja