updated code with more input and output