refactor to return objects instead of dict