Fixed edge case where all inputs are empty, simplified logic