Returning success instead of error for clarity
Refactored write function