fix error in open() and change flags