Another fix with minor performance improvement

Another small fix which adds minor performance gain (and remove some code duplication)