moved RE compilation to its own function