Some bugs fixes