many improvements, tested with real deployments