removed fprintf statements
restaured pieces of code accidentally removed with latest merge
removed unused variables