Fix for setting unit state flags based on @MarkDeVerno's patch