Modified function so it takes in an object