changed code to be an object and updated tests