Would be nice if this code duplication could be avoided somehow.