fixed logic error for output