More refactoring and code simplificaiton.