Adding more fixes as required to remove ActiveRecord errors (see f46e9233ae3a2623ca38120f50b15d8141b68b5c)