Pull this changes into a function
CC @lizlux