Refactoring code to get better score