added support for multiple scopes; changed .each to .find_each for better performance on large tables;