made automatic label detection more flexible