This function got long, can you try to do something about it?