Fix bug in input loop