Bug fixes and made logging more efficient