Updated file with complete code