modifed codeNewAndAppend and changed writing to 12 bit