Some refactoring for cleaner code