Clean up view a bit and move some functions to new files.