Tweaked version to match his updates