Updated with working code