fix a minor bug and adjust code