Some refactoring. to help in debugging