added another if to avoid to read and writes