Fixed weird bug where last few directives aren't replaced