updated code for output and return data