Removed duplicated code. Incremented length for time.
Added checking write results.