updated code with some corrections