Initial import.
Minor refactoring.