logic code refactoring