Added flag stuff and more helpful error messages