Fixed bug with io redirection, code cosmetic changes