Fix logic error and simplify code for status calculation