Some changes to make this work now with REEM

Work in progress, but this should not break anything, only making it work.