Simplify code and remove unreachable check