Modified to be able to work in 3.x