Merged 3 functions into 1