Fixed issues with new line chars. Handles flags correctly