Small bug fixes
Changed data writing