More generic solution for previous commit, now also works when the methods are called by console commands