added callbacks to the functions to ensure synchronous behavior