Added some code refactoring