Solution 96 Refactored

added functions to remove repeating code