refactory code structure