Full code change by Abhinav