Split up the patch, and add some documentation