Realized local logic.
Some refactoring.