correcting several bugs