Can these be extracted into functions? The pyramid o' doom is getting awfully deep.