Implemented next_generation/1.
Fixed edge invalid handling.