Reverted back to old code with logging