Added hook code from 2be. Rewrote it to be static.