Code refactored, undocumented flags support added