refactor code to take directory name
will now iterate over an arbitrary directory