Some refactoring and clean up
Some refactoring and cleanup