Fixed error in handle_sys_write causing a strange behaviour.