writing func implemented
almost complete save function