Added read/write functionality, and minor bug fixes