Some refactoring made.