Added a refactored version, which doesn't require the pandas library.