Some refactoring on the input code