Fix write-read ratio bug, clean up code