Added Michael's final code.