Minor refactor and optimization.