Fixed input bug and nn algorithm