Not strictly necessary, as the C version works fine - but fun to do!