Maybe introduce a function for this insertion logic