Tweaked to make it work with automod