refactoring code and giving last improvement