Clean up and add a bit of documentation