Fixed code to make it more object oriented, its more reusable