code refactoring & a bug fixed.