Converted to be object oriented and more readable