code was changed according to comments