Slightly refactored and cleaned up boilerplate.