I didn't realise this had already been put in GitHub