Re-factored some code.