Ridiculous bug I've introduced...
Here's the code as it should have been all along...