Lots of code clean-ups; using flags package for cleaner argument handling; better optional feature support.