return based on fd equal -1 instead of big if clause