Restructured code to be more adherent to pattern intent.