Updated to use generators