make this thing less one-giant-function-y
CP