Refactor canwrite API for simpler use.
Update unit tests for canwrite module.