improved according to comments