fix bug and clean up useless code;