renamed bad.txt as bad.bad
moved long and wide manipulations into functions and use loop to rbind them