refactoring in dump() function
more refactoring in dump() implementation and related functions