Merged the two functions