Refactored to make more obj oriented