Updated code with requested modifications