refactoring showResult function