Add write APIs and perform refactoring