Some refactoring and brush up.