refactor according to comments