Fixed if logic error and indent issue