Tweaked to make compatible with new Core