Adapted code tp Q 2.0.1