fix logic code, test