updated code by gituser2