Refractor Code

Code complexity eased by utilizing a class.