Bug fixes and log improvments