works but is abyssmally unoptimized