Code cleanup/refactoring and few tweaks.