revised more variable names, simplified code.