added more comments
explained where output goes