Some refactoring to code