Added debug statements to genchan and reformatted for clarity.