Working version. Thanks @ndkerby for pointing out the obvious ommission :)