I should probably consider moving the following functions out for clarity.