Some refactorings to get better and cleaner code.