restructure source hierarchy, add options and refactor the code