Input reading now a separate function.