several bugs fixing