First draft of fixing following; cleaned up some stuff