modified according to comments