code refactor according to comments