Changed code according to comments