Fixing up things here and there and adding documentation.