some refactoring & improvement