Tidied the open source impl a bit.