Code refactoring for the bugfix