Refactored and abstracted more.