for flexibility/testability, could this take an open file object instead of a filepath?