Logging, some promise structure and code cleaning