finished writing code writefunciton not tested yet