split into a few separate funcs.