correcting mapreduce function and adding logic to the converttocommand function