fixing numerous bugs