Handling variable number of inputs