updated logic code