Updated
Added flags and improved code