moving to a callback style to avoid race conditions