Cleanup of truly hideous code