a bug fixed
refactoring the code, make it follow open-close principle