can you try to break this function in smaller parts?