move handling of inputs events to a function