Cleaning up and adding more logging