Updated with proper working code