changed logic code