several bugs fixes