Made some code refactoring