Cleans up code and improves/fixes docs.