neatedne up input code and fixed at least one off by one error.