Move common functionality to separate functions. Create separate objects
for high level algorithms and UI.