change code structure and consolidate redundant methods