Changed function names.
Added support for legacy flags.
Added checking for error conditions.