cleaning code and modulize function, add option feature