Changed flag from bool to int for better interopability.