More locals and minor code refactoring.