Use on_source hook
Move variable assignments to outside on_source hook