Object-oriented version, working well