rewrite of logic code