finished port to 2.7 version