Modified to allow for hooks into the code