moved delay to correct location