Moved all the functions to one unified place