fixed numerous bugs