change routine, fix bugs, add exception