code cleaned
added write hs functional
added errors