fixed comments and made write functions more verbose