2.0 Copied implementation from 1.x version