Final Working Code