added back button functionality. moved  input function