error writing should not be in if, sorry