Holy toledo.  This is _screaming_ REFACTOR ME I AM CRAZY.