code cleanup; big improvements