Working version of code tested in class