code fixed for the new circumstances