Do these functions really need to be nested like this?