Refactored lib.flags

Added tests for the flags library and refactored the code within the library.