fixed the hang. Code still looks like shit.