Some bugs fixing