Add preconditions.
Minor changes on tests.
Update documentation.