refactor build input function