Added bulk of code for logging portion