The two (probably four) functions below can definitely be abstracted into one.