added output,, various refactorings