Refactored to use pandas