fix flags on reading, add a convenience function