Solution code refactored more Object oriented way