Refactored the existing macro extraction code into some reuseable functions and made everything use and be iterators.
Moved flatten_cursor into the main module, as it will be used by almost every function that extracts information.