corrected several bugs