[EDIT] Added write functions.
[EDIT] Another upgraded version.