Merge into 1 function