finished most of function
add some comment