original code (before Brett changes)