This is a big function! Can we break it down some?