Pulled out a few functions.