Refactor code base to reduce common code