Add debug messages. Refactor to make more stable. Set logger format. Etc